<template>
  <div class="list-tab__item">
    <el-tabs>
      <el-tab-pane v-for="(item, index) in list " :key="index" :label="item.title">
        <el-scrollbar height="250px">
          <div class="container" v-for="(item1 , index1) in item.content" :key="index1" @click="clickItem(item1,index1)">
          <div class="avatar" v-if="item1.avatar">
            <el-avatar size="small" :src="item1.avatar"></el-avatar>
          </div>
          <div class="content">
            <div v-if="item1.title" class="title">
              <div>{{ item1.title }}</div>
              <el-tag v-if="item1.tag" size="small" :type="item1.tagType">{{ item1.tag }}</el-tag>
            </div>
            <div v-if="item1.time" class="time">{{ item1.time }}</div>
          </div>
          </div>
          <div class="actions" >
            <div class="a-item" :class="{'border' : i !== actions.length-1}" v-for="(action, i) in actions" :key="1" @click="clickAction(action,i)">
              <div class="a-icon" v-if="action.icon">
                <component :is='`el-icon-${toLine(action.icon)}`'></component>
              </div>
              <div class="a-text">{{ action.text }}</div>
            </div>
          </div>
        </el-scrollbar>
      </el-tab-pane>
    </el-tabs> 
  </div>
</template>

<script setup lang="ts">
import { PropType } from 'vue'
import { ListOptions, ActionOptions, ListItem } from './type'
import { toLine } from '../../../utils';
import { actions } from '../../../views/notification/data';

let props = defineProps({
  //列表内容
  list: {
    type: Array as PropType<ListOptions[]>,
    required: true
  },
  //操作内容
  actions: {
    type: Array as PropType<ActionOptions[]>,
    default: () => []
  }
})

let emits = defineEmits(['clickItem','clickAction'])

const clickItem = (item: ListItem , index: number) => {
  emits('clickItem', {item , index})
}
const clickAction = (actions: ActionOptions, index: number) => {
  emits('clickAction',{actions, index})
}
</script>

<style scoped lang="scss">
.container{
  display: flex;
  align-items: center;
  padding: 12px 15px;
  cursor: pointer;
  &:hover {
    background: #b2d4e7;
  }
  .avatar {
    flex: 1;
  }
  .content {
    flex: 3;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .time {
      font-size: 12px;
      color: #999;
      margin-top: 5px;
    }
  }
}
.actions {
  height: 30px;
  display: flex;
  align-items: center;
  border-top: 1px solid #a9a9a9;
  .a-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    .a-icon {
      margin-right: 4px;
      position: relative;
      top: 2px;
    }
  }
}
.border {
  border-right: 1px solid #a9a9a9;
}
</style>